home *** CD-ROM | disk | FTP | other *** search
- Path: itnews.sc.intel.com!news
- From: Eric Minor <EricX_Minor@ccm.sc.intel.com>
- Newsgroups: comp.lang.c++
- Subject: Re: Problem with polymorphism.
- Date: 5 Jan 1996 02:27:20 GMT
- Organization: Intel - Internet Engineering Group
- Message-ID: <4ci2a8$hhi@itnews.sc.intel.com>
- References: <4cgjkr$fcr@oznet07.ozemail.com.au>
- NNTP-Posting-Host: eminorx-desk.sc.intel.com
-
-
- regarding your polymorphism problem...
-
- You seem to have a grasp of what the problem is. You're right,
- you can't call TKey::GetKey() because it doesn't exist. It
- doesn't make sense to me to start your polymorphism at the
- TKey level when the data you wish to compare doesn't even
- exist at that level. It seems to me you must have the 'int key'
- data member defined at the TKey level. You mention that causes
- you other problems...I'd be interested to know what that problem
- is. Of course, if you want to access this data member in
- derived classes you would need to put it in the protected
- or public sections of TKey. Also, since you mention that you're
- a beginner, I'll chime in that the behavior you are implementing
- in the Compare() method might be more typically implemented
- with the overridden equality operator with prototype as follows:
-
- int TKey::operator==(const TKey& rhs);
-
- Perhaps it makes more sense for you to use a separate Compare()
- method since you are interested in a tri-state return.
-
- > But I don't know what would happen if I was to declare
- > the original pure virtual function as:
- >
- > virtual int Compare(void) = 0;
- >
- > and then in all derived classes declare it as:
- >
- > virtual int Compare(iKey *key2);
- >
- > etc. Can I overload virtual functions like that safely?
-
- No you cannot. Virtual function overrides must have identical
- signatures.
-
- Hope this helps.
-
- - Eric Minor
-
-